package com.cetcs.kmga.dataManager.util.socket;

import com.google.common.collect.Maps;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description :本地缓存WebSocketSession实例
 * Created by XingWen on 2016/12/23.
 */
public class WSSessionLocalCache implements Serializable {
    private static Map<String, UserSocket> wsSessionCache = Maps.newHashMap();

    public static boolean exists(String userId){
        if(!wsSessionCache.containsKey(userId)){
            return false;
        }else{
            return true;
        }
    }

    public static void put(String userId, UserSocket userSocket){
        wsSessionCache.put(userId, userSocket);
    }

    public static UserSocket get(String userId){
        return wsSessionCache.get(userId);
    }

    public static void remove(String userId){
        wsSessionCache.remove(userId);
    }

    public static List<UserSocket> getAllSessions(){
        return new ArrayList<>(wsSessionCache.values());
    }
}
